{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e3b066b8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Zen of Python, by Tim Peters\n",
      "\n",
      "Beautiful is better than ugly.\n",
      "Explicit is better than implicit.\n",
      "Simple is better than complex.\n",
      "Complex is better than complicated.\n",
      "Flat is better than nested.\n",
      "Sparse is better than dense.\n",
      "Readability counts.\n",
      "Special cases aren't special enough to break the rules.\n",
      "Although practicality beats purity.\n",
      "Errors should never pass silently.\n",
      "Unless explicitly silenced.\n",
      "In the face of ambiguity, refuse the temptation to guess.\n",
      "There should be one-- and preferably only one --obvious way to do it.\n",
      "Although that way may not be obvious at first unless you're Dutch.\n",
      "Now is better than never.\n",
      "Although never is often better than *right* now.\n",
      "If the implementation is hard to explain, it's a bad idea.\n",
      "If the implementation is easy to explain, it may be a good idea.\n",
      "Namespaces are one honking great idea -- let's do more of those!\n"
     ]
    }
   ],
   "source": [
    "import this"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "353cd552",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "helloWorld.\n"
     ]
    }
   ],
   "source": [
    "print(\"helloWorld.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "353cd079",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 1\n",
    "b = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "24590527",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 2 3\n"
     ]
    }
   ],
   "source": [
    "print(a,b,a+b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "51f4dc4c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "print(b-a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "518b9ced",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "cdcbeb9a",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd = np.array([[1,2,3],[4,5,6]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "61ab21fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]]\n"
     ]
    }
   ],
   "source": [
    "print(nd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "478b86cd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "print(type(nd))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "9f0a794c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f0c404c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "f1e94239",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.5"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "01b18940",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd1= np.array([\"1\",\"2\",\"3\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "136b1542",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['1' '2' '3']\n"
     ]
    }
   ],
   "source": [
    "print(nd1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "01a4d30c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 类型转换\n",
    "# numpy是用于科学计算，每一个元素必须都是数值型的\n",
    "nd1 = nd1.astype(\"float\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "a962949c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.0"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd1.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "4e49fa30",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd2 = np.array([[1,2,3],[4,5,6],[7,8,9]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "90dee2c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]\n",
      " [7 8 9]]\n"
     ]
    }
   ],
   "source": [
    "print(nd2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "72caca20",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[4, 5, 6]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd2[1:2:1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "87a59b0d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2, 3],\n",
       "       [5, 6]])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# nd2[ 行的切片,列的切片 ]\n",
    "nd2[0:2:1,1:3:1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "04d35861",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd3 = np.array([[0,1,2,3,4,5],\n",
    "          [10,11,12,13,14,15],\n",
    "          [20,21,22,23,24,25],\n",
    "          [30,31,32,33,34,35],\n",
    "          [40,41,42,43,44,45],\n",
    "          [50,51,52,53,54,55]]\n",
    "        )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "bab8ee5c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4  5]\n",
      " [10 11 12 13 14 15]\n",
      " [20 21 22 23 24 25]\n",
      " [30 31 32 33 34 35]\n",
      " [40 41 42 43 44 45]\n",
      " [50 51 52 53 54 55]]\n"
     ]
    }
   ],
   "source": [
    "print(nd3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "3719f083",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 4]])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3[ 0:1:1,3:5:1 ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "52567fe8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[20, 22, 24],\n",
       "       [40, 42, 44]])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3[2:5:2,0:5:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "00514580",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2],\n",
       "       [12],\n",
       "       [22],\n",
       "       [32],\n",
       "       [42],\n",
       "       [52]])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3[::,2:3:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "aa449b8d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[44, 45],\n",
       "       [54, 55]])"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3[4::,4::]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "69a2112e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1, 12, 23])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# nd3[(待取元素0轴的坐标),(待取元素1轴的坐标)]\n",
    "nd3[(0,1,2),(1,2,3)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "7e10c2b2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[False, False, False, False, False, False],\n",
       "       [False, False, False, False, False, False],\n",
       "       [False, False, False, False, False, False],\n",
       "       [False, False, False,  True,  True,  True],\n",
       "       [ True,  True,  True,  True,  True,  True],\n",
       "       [ True,  True,  True,  True,  True,  True]])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3>32"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "8dedca21",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  2,  4, 10, 12, 14, 20, 22, 24, 30, 32, 34, 40, 42, 44, 50, 52,\n",
       "       54])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3[nd3%2==0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "693198c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ True, False,  True, False,  True, False],\n",
       "       [ True, False,  True, False,  True, False],\n",
       "       [ True, False,  True, False,  True, False],\n",
       "       [ True, False,  True, False,  True, False],\n",
       "       [ True, False,  True, False,  True, False],\n",
       "       [ True, False,  True, False,  True, False]])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3%2==0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "9f158fb0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0, 10, 20, 30, 40, 50],\n",
       "       [ 1, 11, 21, 31, 41, 51],\n",
       "       [ 2, 12, 22, 32, 42, 52],\n",
       "       [ 3, 13, 23, 33, 43, 53],\n",
       "       [ 4, 14, 24, 34, 44, 54],\n",
       "       [ 5, 15, 25, 35, 45, 55]])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd3.transpose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "7d6d50a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 矩阵的运算\n",
    "nd4 = np.array([[1,2,3],[4,5,6]])\n",
    "nd5 = np.array([[2,3,4],[1,2,3]])\n",
    "nd6 = np.array([[1,2],[2,3],[3,4]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "4dcb2b48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 5, 7],\n",
       "       [5, 7, 9]])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# + - * /\n",
    "# 对位运算\n",
    "nd4 + nd5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "c8eb0c08",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1, -1, -1],\n",
       "       [ 3,  3,  3]])"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4 - nd5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "1426d045",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2,  6, 12],\n",
       "       [ 4, 10, 18]])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4 * nd5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "69fea16c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.5       , 0.66666667, 0.75      ],\n",
       "       [4.        , 2.5       , 2.        ]])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4 / nd5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "f324698e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[14, 20],\n",
       "       [32, 47]])"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 矩阵相乘不能直接使用*\n",
    "# 需要用到 np.dot()\n",
    "np.dot(nd4,nd6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "19743906",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd7 = np.array([1,2,3,4,5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "b3e0040d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.84147098,  0.90929743,  0.14112001, -0.7568025 , -0.95892427])"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sin(nd7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "fb528d58",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.54030231, -0.41614684, -0.9899925 , -0.65364362,  0.28366219])"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.cos(nd7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "17874329",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.        , 0.69314718, 1.09861229, 1.38629436, 1.60943791])"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.log(nd7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "5e53e2ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.4142135623730951"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(nd7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c5d5b47",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
